#!/usr/bin/php5
<?
include "WikiParser.php";

if ( $argc == "2" )
{
	// Check if file exists
	if (!file_exists($argv[1]))
	{
		printf("ERROR: File does not exist!\n");
		exit(1);
	}

	$data = array();
	$fd = fopen ( $argv[1], "r");
	while (!feof ($fd))
	{
		$buffer = fgets($fd, 4096);
		array_push( $data, preg_replace( "/^(.*)\n/","\\1",$buffer ) );
	}
	fclose ($fd);

	$wikitext = join( "\r\n", $data );

	$wikiparser = new WikiParser();
	$htmlresult = $wikiparser->parse($wikitext);
	echo $htmlresult;
}
else
{
	echo "Usage: wiki2cool.php <wikifile.txt>\n";
}
?>
